package com.enba.boot.security.jwt;

import com.enba.boot.core.base.Result;
import com.enba.boot.security.enums.AuthStatusEnum;
import java.io.IOException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.access.AccessDeniedHandler;

/** 当用户访问受限资源时，如果权限不足，会触发该方法 */
public class DefaultJwtAccessDeniedHandler implements AccessDeniedHandler {
  @Override
  public void handle(
      HttpServletRequest request, HttpServletResponse response, AccessDeniedException e)
      throws IOException {
    Result.render(
        response,
        Result.err(AuthStatusEnum.ACCESS_DENIED.getCode(), AuthStatusEnum.ACCESS_DENIED.getMsg()));
  }
}
